package edu.nyu.cyrus;

import java.sql.Date;
import java.text.DateFormat;
import java.util.Comparator;

public class CompareByDOB implements Comparator<PersonDataModel>{

	public int compare(PersonDataModel o1, PersonDataModel o2) {
		String dob1[] = o1.getDob().split("/");
		String dob2[] = o2.getDob().split("/");		
		String temp1 = String.format("%4d-%02d-%02d", Integer.parseInt(dob1[2]),Integer.parseInt(dob1[0]),Integer.parseInt(dob1[1]));
		String temp2 = String.format("%4d-%02d-%02d", Integer.parseInt(dob2[2]),Integer.parseInt(dob2[0]),Integer.parseInt(dob2[1]));
		
		Date d1 = Date.valueOf(temp1);
		Date d2 = Date.valueOf(temp2);
		
		return d1.compareTo(d2) > 0 ? 1 : 0;
	}
}
